/*
*  Copyright (c) 2014, Facebook, Inc.
*  All rights reserved.
*
*  This source code is licensed under the BSD-style license found in the
*  LICENSE file in the root directory of this source tree. An additional grant
*  of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include <d3d11.h>
#include <mutex>
#include <windows.h>

#define ERROR_VIDEO_ENCODING_CAUSE_ERRORS       100
#define ERROR_AUDIO_ENCODING_CAUSE_ERRORS       200
#define ERROR_TRANSCODING_MUXING_CAUSE_ERRORS   300
#define ERROR_RTMP_CAUSE_ERRORS                 400
#define ERROR_GRAPHICS_CAPTURE_ERRORS           500
#define ERROR_CONFIGURATION_ERRORS              600
#define ERROR_SYSTEM_ERRORS                     700
#define ERROR_ENCODING_CAPABILITY               800

// SAFE_RELEASE macro
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(a) if (a) { a->Release(); a= NULL; }
#endif

namespace FBCapture {
  namespace Common {

    typedef enum {
      // Common error codes
      FBCAPTURE_STATUS_OK, FBCAPTURE_STATUS_SW_ENCODER_ENABLED = 0,
      FBCAPTURE_STATUS_ENCODE_IS_NOT_READY,
      FBCAPTURE_STATUS_NO_INPUT_FILE,
      FBCAPTURE_STATUS_FILE_READING_ERROR,
      FBCAPTURE_STATUS_OUTPUT_FILE_OPEN_FAILED,
      FBCAPTURE_STATUS_OUTPUT_FILE_CREATION_FAILED,
      FBCAPTURE_STATUS_DXGI_CREATING_FAILED,
      FBCAPTURE_STATUS_DEVICE_CREATING_FAILED,

      // Video/Image encoding specific error codes      
      FBCAPTURE_STATUS_ENCODE_INIT_FAILED = ERROR_VIDEO_ENCODING_CAUSE_ERRORS,
      FBCAPTURE_STATUS_ENCODE_SET_CONFIG_FAILED,
      FBCAPTURE_STATUS_ENCODER_CREATION_FAILED,
      FBCAPTURE_STATUS_INVALID_TEXTURE_POINTER,
      FBCAPTURE_STATUS_CONTEXT_CREATION_FAILED,
      FBCAPTURE_STATUS_TEXTURE_CREATION_FAILED,
      FBCAPTURE_STATUS_TEXTURE_RESOURCES_COPY_FAILED,
      FBCAPTURE_STATUS_IO_BUFFER_ALLOCATION_FAILED,
      FBCAPTURE_STATUS_ENCODE_PICTURE_FAILED,
      FBCAPTURE_STATUS_ENCODE_FLUSH_FAILED,
      FBCAPTURE_STATUS_INVALID_TEXTURE_RESOLUTION,
      FBCAPTURE_STATUS_ENCODE_DESTROY_FAILED,

      // WIC specific error codes
      FBCAPTURE_STATUS_WIC_SAVE_IMAGE_FAILED,

      // Audio encoding specific error codes
      FBCAPTURE_STATUS_AUDIO_DEVICE_ENUMERATION_FAILED = ERROR_AUDIO_ENCODING_CAUSE_ERRORS,
      FBCAPTURE_STATUS_AUDIO_CLIENT_INIT_FAILED,
      FBCAPTURE_STATUS_WRITING_WAV_HEADER_FAILED,
      FBCAPTURE_STATUS_RELEASING_WAV_FAILED,

      // Transcoding and muxing specific error codes
      FBCAPTURE_STATUS_MF_CREATION_FAILED = ERROR_TRANSCODING_MUXING_CAUSE_ERRORS,
      FBCAPTURE_STATUS_MF_INIT_FAILED,
      FBCAPTURE_STATUS_MF_CREATING_WAV_FORMAT_FAILED,
      FBCAPTURE_STATUS_MF_TOPOLOGY_CREATION_FAILED,
      FBCAPTURE_STATUS_MF_TOPOLOGY_SET_FAILED,
      FBCAPTURE_STATUS_MF_TRANSFORM_NODE_SET_FAILED,
      FBCAPTURE_STATUS_MF_MEDIA_CREATION_FAILED,
      FBCAPTURE_STATUS_MF_HANDLING_MEDIA_SESSION_FAILED,

      // WAMEDIA muxing specific error codes
      FBCAPTURE_STATUS_WAMDEIA_MUXING_FAILED,

      // More MF error codes
      FBCAPTURE_STATUS_MF_STARTUP_FAILED,
      FBCAPTURE_STATUS_MF_TRANSFORM_CREATION_FAILED,
      FBCAPTURE_STATUS_MF_SOURCE_READER_CREATION_FAILED,
      FBCAPTURE_STATUS_MF_STREAM_SELECTION_FAILED,
      FBCAPTURE_STATUS_MF_MEDIA_TYPE_CREATION_FAILED,
      FBCAPTURE_STATUS_MF_MEDIA_TYPE_CONFIGURATION_FAILED,
      FBCAPTURE_STATUS_MF_MEDIA_TYPE_SET_FAILED,
      FBCAPTURE_STATUS_MF_MEDIA_TYPE_GET_FAILED,
      FBCAPTURE_STATUS_MF_CREATE_WAV_FORMAT_FROM_MEDIA_TYPE_FAILED,
      FBCAPTURE_STATUS_MF_TRANSFORM_OUTPUT_STREAM_INFO_FAILED,
      FBCAPTURE_STATUS_MF_CREATE_MEMORY_BUFFER_FAILED,
      FBCAPTURE_STATUS_MF_CREATE_SAMPLE_FAILED,
      FBCAPTURE_STATUS_MF_SAMPLE_ADD_BUFFER_FAILED,
      FBCAPTURE_STATUS_MF_READ_SAMPLE_FAILED,
      FBCAPTURE_STATUS_MF_TRANSFORM_FAILED,
      FBCAPTURE_STATUS_MF_BUFFER_LOCK_FAILED,

      // Medatada injection error codes
      FBCAPTURE_STATUS_METADATA_INVALID_XML,
      FBCAPTURE_STATUS_METADATA_INJECTION_FAILED,

      // RTMP specific error codes
      FBCAPTURE_STATUS_INVALID_FLV_HEADER = ERROR_RTMP_CAUSE_ERRORS,
      FBCAPTURE_STATUS_INVALID_STREAM_URL,
      FBCAPTURE_STATUS_RTMP_CONNECTION_FAILED,
      FBCAPTURE_STATUS_RTMP_DISCONNECTED,
      FBCAPTURE_STATUS_SENDING_RTMP_PACKET_FAILED,

      // Graphics capture error codes
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_INIT_FAILED = ERROR_GRAPHICS_CAPTURE_ERRORS,
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_INVALID_TEXTURE,
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_OPEN_SHARED_RESOURCE_FAILED,
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_KEYED_MUTEX_ACQUIRE_FAILED,
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_KEYED_ACQUIRE_ACQUIRE_SYNC_FAILED,
      FBCAPTURE_STATUS_GRAPHICS_DEVICE_CAPTURE_KEYED_ACQUIRE_RELASE_SYNC_FAILED,

      // Configuration error codes
      FBCAPTURE_STATUS_MIC_NOT_CONFIGURED = ERROR_CONFIGURATION_ERRORS,
      FBCAPTURE_STATUS_MIC_REQUIRES_ENUMERATION,
      FBCAPTURE_STATUS_MIC_DEVICE_NOT_SET,
      FBCAPTURE_STATUS_MIC_ENUMERATION_FAILED,
      FBCAPTURE_STATUS_MIC_SET_FAILED,
      FBCAPTURE_STATUS_MIC_UNSET_FAILED,
      FBCAPTURE_STATUS_MIC_INDEX_INVALID,
      FBCAPTURE_STATUS_CAMERA_NOT_CONFIGURED,
      FBCAPTURE_STATUS_CAMERA_REQUIRES_ENUMERATION,
      FBCAPTURE_STATUS_CAMERA_DEVICE_NOT_SET,
      FBCAPTURE_STATUS_CAMERA_ENUMERATION_FAILED,
      FBCAPTURE_STATUS_CAMERA_SET_FAILED,
      FBCAPTURE_STATUS_CAMERA_UNSET_FAILED,
      FBCAPTURE_STATUS_CAMERA_INDEX_INVALID,
      FBCAPTURE_STATUS_LIVE_CAPTURE_SETTINGS_NOT_CONFIGURED,
      FBCAPTURE_STATUS_VOD_CAPTURE_SETTINGS_NOT_CONFIGURED,
      FBCAPTURE_STATUS_PREVIEW_CAPTURE_SETTINGS_NOT_CONFIGURED,
      FBCAPTURE_STATUS_SCREENSHOT_CAPTURE_SETTINGS_NOT_CONFIGURED,

      // System error codes
      FBCAPTURE_STATUS_SYSTEM_INITIALIZE_FAILED = ERROR_SYSTEM_ERRORS,
      FBCAPTURE_STATUS_SYSTEM_ENCODING_TEXTURE_CREATION_FAILED,
      FBCAPTURE_STATUS_SYSTEM_PREVIEW_TEXTURE_CREATION_FAILED,
      FBCAPTURE_STATUS_SYSTEM_ENCODING_TEXTURE_FORMAT_CREATION_FAILED,
      FBCAPTURE_STATUS_SYSTEM_SCREENSHOT_TEXTURE_FORMAT_CREATION_FAILED,
      FBCAPTURE_STATUS_SYSTEM_CAPTURE_IN_PROGRESS,
      FBCAPTURE_STATUS_SYSTEM_CAPTURE_NOT_IN_PROGRESS,
      FBCAPTURE_STATUS_SYSTEM_CAPTURE_TEXTURE_NOT_RECEIVED,
      FBCAPTURE_STATUS_SYSTEM_CAMERA_OVERLAY_FAILED,
      FBCAPTURE_STATUS_SYSTEM_CAPTURE_PREVIEW_FAILED,
      FBCAPTURE_STATUS_SYSTEM_CAPTURE_PREVIEW_NOT_IN_PROGRESS,

      // Encoding capability error codes
      FBCAPTURE_STATUS_UNSUPPORTED_ENCODING_ENVIRONMENT = ERROR_ENCODING_CAPABILITY,
      FBCAPTURE_STATUS_UNSUPPORTED_GRAPHICS_CARD_DRIVER_VERSION,
      FBCAPTURE_STATUS_UNSUPPORTED_GRAPHICS_CARD,
      FBCAPTURE_STATUS_UNSUPPORTED_OS_VERSION,
      FBCAPTURE_STATUS_UNSUPPORTED_OS_PROCESSOR,
      FBCAPTURE_STATUS_MULTIPLE_ENCODING_SESSION,

    }FBCAPTURE_STATUS;

    namespace VrDeviceType {
      typedef enum {
        NONE,
        OCULUS_RIFT,
        HTC_VIVE,
      }VRDeviceType;
    }

    namespace StereoMode {
      typedef enum {
        NONE,
        TOP_BOTTOM,
        LEFT_RIGHT
      }STEREO_MODE;
    }

    namespace ProjectionType {
      typedef enum {
        NONE,
        EQUIRECT,
        CUBEMAP,
        SINGLE_FISHEYE
      }PROJECTIONTYPE;
    }

    typedef enum {
      NVIDIA,
      AMD,
      UNSUPPORTED_DEVICE
    }GRAPHICS_CARD;
  }
}
